package routers

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	controllers "vote.zozoo.net/internal/controllers/order"
	repository "vote.zozoo.net/internal/repostory/order"
	service "vote.zozoo.net/internal/services/order"
)

func initOrderRouter(r *gin.RouterGroup, db *gorm.DB) {
	or := repository.NewOrderGormRepository(db)
	os := service.NewOrderServiceImpl(or)
	oc := controllers.NewOrderController(os)
	group := r.Group("/orders")
	{
		group.POST("", oc.CreateOrder)
		group.GET("/:orderNo", oc.GetByOrderNo)
		group.GET("/page/:orderNo", oc.GetPageByOrderNo)
		group.GET("", oc.GetAllOrders)
		group.GET("/user/:userId", oc.GetOrdersByUserID)
		group.PUT("/:orderNo", oc.UpdateOrder)
		group.PATCH("/:orderNo/status", oc.UpdateOrderStatus)
		group.DELETE("/:orderNo", oc.DeleteOrder)
	}
}
